package com.dyna.auth.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dyna.api.domain.entity.SysOAuth2RefreshToken;
import com.dyna.enums.DeleteValueEnum;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface OAuth2RefreshTokenMapper extends BaseMapper<SysOAuth2RefreshToken> {

    default SysOAuth2RefreshToken selectByRefreshToken(String refreshToken) {
        LambdaQueryWrapper<SysOAuth2RefreshToken> query = new LambdaQueryWrapper<>();
        query.eq(SysOAuth2RefreshToken::getDelFlag, DeleteValueEnum.DELETE.getValue());
        query.eq(SysOAuth2RefreshToken::getRefreshToken, refreshToken);
        return this.selectOne(query);
    }
    default int deleteByRefreshToken(String refreshToken) {
        return update(new LambdaUpdateWrapper<SysOAuth2RefreshToken>()
                .set(SysOAuth2RefreshToken::getDelFlag, DeleteValueEnum.DELETED.getValue())
                .eq(SysOAuth2RefreshToken::getRefreshToken, refreshToken));
    }

}